package main

import (
	"fmt"
	"gitee.com/hakwolf/taibak/internal/models"
	"gitee.com/hakwolf/taibak/internal/routers/user"
	"github.com/ying32/govcl/vcl"
	"github.com/ying32/govcl/vcl/types"
)

// ::private::
type TLoginFormFields struct {
}

func (f *TLoginForm) OnSBLoginClick(sender vcl.IObject) {
	usr := f.EditUserName.Text()
	if usr == "" {
		fmt.Println("输入用户名吧")
		f.EditUserName.SetFocus()
		return
	}
	pwd := f.EditPassword.Text()
	if pwd == "" {
		fmt.Println("输入密码吧。")
		f.EditPassword.SetFocus()
		return
	}
	userinfo := models.User{Name: usr, Password: pwd}
	err, _ := user.UIValidateLogin(userinfo)
	if err != nil {
		vcl.ShowMessage(err.Error())
		return
	}

	isLogin = true
	f.Close()

	MainForm.Show()

}

func (f *TLoginForm) OnFormClose(sender vcl.IObject, closeAction *types.TCloseAction) {
	if !isLogin {
		vcl.Application.Terminate()
	}
}

func (f *TLoginForm) OnFormCreate(sender vcl.IObject) {

}

func (f *TLoginForm) OnFormShow(sender vcl.IObject) {

}

func (f *TLoginForm) OnBTIPManageClick(sender vcl.IObject) {
	var ipId int
	if f.CBServer.ItemIndex() != -1 {
		bevel := vcl.AsBevel(f.CBServer.Items().Objects(f.CBServer.ItemIndex()))
		if bevel != nil {
			ipId = bevel.Tag()
		}
	}

	fmLoginIP := NewFmLoginIPEdit(f)
	fmLoginIP.ShowModal()
	f.showall()
	if ipId == 0 {
		f.CBServer.SetItemIndex(-1)
	} else {
		//f.setIpIdItemIndex(ipId)
	}

}

func (f *TLoginForm) showall() {

}
